<template>
  <div class="flex flex-col h-full">
    <SearchContainer @search="getData" @reset="() => formRef.resetFields()">
      <a-form ref="formRef" class="form-style-flex" :model="formState">
        <a-form-item name="lbmc" label="" class="w-64 mr-3">
          <a-input v-model:value="formState.lbmc" allow-clear placeholder="销售名称/助记码" />
        </a-form-item>
        <a-form-item name="returnDateRange" label="缴费时间" class="w-72 mr-3">
          <a-range-picker v-model:value="formState.dateRange" format="YYYY-MM-DD" value-format="YYYY-MM-DD" allow-clear />
        </a-form-item>
        <a-form-item name="pyjm" label="患者" class="w-[250px] ml-2 mr-3">
          <a-input v-model:value="formState.pyjm" allow-clear placeholder="姓名/助记码/手机号/卡号" />
        </a-form-item>
        <a-form-item name="ysmc" label="医生" class="w-64 mr-3">
          <a-input v-model:value="formState.ysmc" allow-clear placeholder="请输入" />
        </a-form-item>
        <a-form-item name="xmlb" label="项目类别">
          <a-select
            v-model:value="formState.xmlb"
            :max-tag-text-length="3"
            max-tag-count="responsive"
            :virtual="false"
            class="!w-64"
            :options="options"
            mode="multiple"
            placeholder="请选择"
          />
        </a-form-item>
      </a-form>
    </SearchContainer>
    <a-card class="mt-2 flex-1">
      <div class="flex justify-end mb-2">
        <BaseExport
          type="门诊"
          name="视光医嘱项目查询"
          code="001175"
          :search-params="{ chargeTimeStart: formState.dateRange?.[0], chargeTimeEnd: formState.dateRange?.[1], ...formState }"
          >导出</BaseExport
        >
      </div>
      <BaseTable fill bordered column-code="001175" :loading="loading" :data-source="tableData" :pagination="pagination">
        <template #bodyCell="{ column, index, record }">
          <template v-if="column.dataIndex == 'xh'">
            {{ index + 1 }}
          </template>
          <template v-if="column.dataIndex === 'mc'">
            <MedicineInfo :value="{ mc: record.mc, gg: record.gg }" />
          </template>
          <template v-if="column.dataIndex === 'zzcf'">
            <!-- 1：远用 2：近用 -->
            <a-tooltip placement="topLeft">
              <template #title
                >{{ record.longOrShort === '1' ? '远用' : '近用' }}<br />
                {{ record.zzcfyy }}<br />
                {{ record.zzcfzy }}</template
              >
              <span class="cursor-pointer"
                >{{ record.longOrShort === '1' ? '远用' : '近用' }}
                {{ record.zzcfyy }}
                {{ record.zzcfzy }}</span
              >
            </a-tooltip>
          </template>
        </template>
      </BaseTable>
    </a-card>
  </div>
</template>

<script setup>
import { ref } from 'vue'
import dayjs from 'dayjs'
// import { message } from 'ant-design-vue'
import SearchContainer from '@/components/SearchContainer'
// import { formatAmount } from '@/utils/format.js'

const formRef = ref(null)
const options = ref([])
const formState = ref({
  dateRange: [dayjs().format('YYYY-MM-DD'), dayjs().format('YYYY-MM-DD')],
  lbmc: '',
  pyjm: '',
  ysmc: '',
  yzlbList: []
})

const getProjectList = async () => {
  const { code, data } = await post('/drugStorage/comprehenive/getMedicalProjectList')
  if (code !== 0) return
  options.value = data.map((item) => {
    return {
      label: item.mc,
      value: item.mc
    }
  })
}

const { loading, tableData, pagination, getData } = useTable({
  url: '/outp/outpClinicalOrder/getChargedSgMzyzbList',
  immediate: true,
  params: formState.value,
  formatParams: (params) => {
    return {
      ...params,
      chargeTimeStart: params['dateRange']?.[0],
      chargeTimeEnd: params['dateRange']?.[1]
    }
  }
})

onMounted(() => {
  getProjectList()
})
</script>
